package com.example.exam.logInfo.controller;

import com.example.exam.common.ResultBean;
import com.example.exam.common.ResultBeanCodeEnum;
import com.example.exam.db.PageInfoBean;
import com.example.exam.logInfo.service.LogInfoService;
import com.example.exam.user.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/logInfoController")
public class LogInfoController {
    @Autowired
    LogInfoService ls;
    @Autowired
    UserService us;
    @RequestMapping("/selectlog")
    @ResponseBody
        /** 
            * @Description: 日志列表
            * @Param: [request, page, limit] 
            * @return: java.lang.Object 
            * @Author: xhw
            * @Date: 2021/7/26 
            */ 
    public Object list(HttpServletRequest request, Integer page, Integer limit) {
        ResultBean resultBean = new ResultBean();
        String beginningAndEndingTime=request.getParameter("beginningAndEndingTime");
        //System.out.println(beginningAndEndingTime);
        String beginTime=null;
        String endTime=null;
        if (StringUtils.isNotEmpty(beginningAndEndingTime)){
            beginTime=beginningAndEndingTime.split("~")[0];
            endTime=beginningAndEndingTime.split("~")[1];
        }
        try {
            PageInfoBean list = ls.toList(page,limit,beginTime,endTime);
            resultBean.setCode(ResultBeanCodeEnum.OPERA_SUCCESS.getCode());
            resultBean.setMsg(ResultBeanCodeEnum.OPERA_SUCCESS.getMsg());
            resultBean.fillData(list);
            return resultBean;
        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setCode(ResultBeanCodeEnum.OPERA_EXCEPTION.getCode());
            resultBean.setMsg(ResultBeanCodeEnum.OPERA_EXCEPTION.getMsg());
            return resultBean;
        }
    }
}
